<div id="large-photo">
  <h1><?php echo safe_output($photo['title']); ?></h1>
  <a href="photos/original/<?php echo $photo['id']; ?>.jpg"><img src="photos/large/<?php echo $photo['id']; ?>.jpg" alt="<?php echo safe_output($photo['title']); ?>" /></a>


	<script language="Javascript">
	function showAlert(){
		alert ("This is a Javascript Alert")
	}

	function showOrHideComments(){
		if( document.getElementById('comments') ){

			var whichEl = document.getElementById('comments');

			if( whichEl.style.display == 'block' ){

				whichEl.style.display = 'none';
			}
			else{
				whichEl.style.display = 'block';
			}
		}
	}
	</script>
	
	
	<?php
	function insert_comment_for_pic($comment, $author, $id){
		$cxn = db_connect();
		$result = mysql_query ("INSERT INTO photos_comments (text, author, photo_id) VALUES ('$comment', '$author','$id')");
		return $result;
	}

	function get_all_comments_for_pic($id){
		$cxn = db_connect();
		logToFile("SELECT * FROM photos_comments where photo_id='$id' order by date desc");
		$result = mysql_query("SELECT * FROM photos_comments where photo_id='$id' order by date desc");
		return $result;
	}

	function logToFile($msg)
	{
		$filename = "log.txt";
		// open file
		$fd = fopen($filename, "a");
		// append date/time to message
		$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " . $msg;
		// write string
		fwrite($fd, $str . "\n");
		// close file
		fclose($fd);

		//error_log("You messed up!", 3, "log.txt");
	}



	echo '<br/><a href="javascript:showOrHideComments();">Show/Hide/Add Comments</a>';
	echo '<span id="commentsCount"></span>';
	
	echo '<form name="comments" style="display:none"  id="comments" action="'.$_SERVER['PHP_SELF'].'?view=show&id='.$photo['id'].'&addComment=true" method="post">';

	echo '<p><table style="font-size: 2.0em;">';
	echo '<tr><td>Comment</td><td><textarea  type="text" name="comment"  cols="45" rows="6" wrap="hard" style="overflow-x: hidden;"></textarea></td></tr>';
	echo '<tr><td>Author </td><td><input type="text" name="author" size="51"></td></tr>';
	echo '</table>';
	echo '<input type="submit" name="submit_comment" value="Post Comment!"></p>';
	if (isset($_GET['addComment']) && $_GET['addComment'] == "true")
	{
		if (isset($_POST['comment']))
		{
			$comment = $_POST['comment'];

			if ($comment == '')
			{
				unset($comment);
			}
		}
		if (isset($_POST['author']))
		{
			$author = $_POST['author'];

			if ($author == '')
			{
				unset($author);
			}
		}
		if (isset($comment) && isset($author))
		{
			$result = insert_comment_for_pic($comment, $author, $photo['id']);

			if ($result == 'true')
			{
				echo "<p>Comment added successfully!</p>";
			}
			else
			{
				echo "<p>Comment not added!</p>";
			}
		}
	}

	
	$allComments = get_all_comments_for_pic($photo['id']);
	
	//show the number of comments - adds text to previously added tag
	$commentsCount=0;
	if(mysql_num_rows($allComments) > 0){
		$commentsCount = mysql_num_rows($allComments);
	}
	$commentsCountText = '&nbsp;&nbsp;(There are '.$commentsCount.' comments for this article)';
	echo '<br/>
	<script type="text/javascript">
	function changeText(){
		document.getElementById(\'commentsCount\').innerHTML = \''.$commentsCountText.'\';
	}
	changeText();
	</script>';


	for( $i = 0; $i < mysql_num_rows( $allComments ); $i++ )
	{
		$myrow = mysql_fetch_assoc( $allComments );
		printf ("<p>%s<br/>%s, %s", $myrow["text"], $myrow["author"],$myrow["date"]);
	}

	echo '</form>'
	?>



</div>

<div id="large-photo-info">
<span class="votes">Votes <?php echo $photo['vote_cache']; ?> ( <a href="index.php?view=show&id=<?php echo $photo['id']; ?>&vote=1">Vote up</a> )</span>

<span class="created-at">@ <?php echo format_date($photo['created_at']); ?></span><br/><br/>
Full Name: &nbsp;<span class="votes"><?php echo safe_output($photo['fullname']); ?></span>

<span class="tags">
Tags:        <?php $tags = photo_tags($photo['id']); ?>
        <?php foreach($tags as $tag): ?>
             <a href="index.php?view=by_tag&tag=<?php echo safe_output($tag['name']); ?>"><?php echo safe_output($tag['name']); ?></a>
				<?php endforeach; ?>
      </span>

<h2>Theme <a href="index.php?view=themes&theme_id=<?php echo $photo['theme_id']; ?>"><?php echo safe_output($photo['theme']); ?><a/></h2>
<?php foreach($photos as $photo): ?>
<a href="index.php?view=show&id=<?php echo $photo['id']; ?>" class="home-pic-link"><img alt="<?php echo safe_output($photo['title']); ?>" src="photos/small/<?php echo $photo['id']; ?>.jpg"></a>
<?php endforeach; ?>








<div class="clear-fix"></div>
</div>
